﻿<script type="text/javascript"> 
    var ip = "http://59.78.38.12:927";
    var roomidglobal = -1;
    var xmlhttp;
    var theflag = @ViewBag.theflag;

    function aaaa(){
        theflag = 1;
    }
    var tttt=setInterval(ready,2000);

 
    function ready() {
        if (theflag == 0) {
            window.location = ip + "/Home/Room/?uname=" +
                   document.getElementById("uname").innerHTML + "&roomid=" + document.getElementById("roomid").innerHTML
                +"&theflag="+theflag;
            return;
        }
   /*     if (roomidglobal == -1) {
            window.clearInterval(tttt);
            setInterval(ready, 1000);
        }*/
        roomidglobal = document.getElementById("roomid").innerHTML;


        xmlhttp = null;
        if (window.XMLHttpRequest) {// code for all new browsers
            xmlhttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {// code for IE5 and IE6
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (xmlhttp != null) {
            xmlhttp.onreadystatechange = state_Change;
            xmlhttp.open("GET", ip+"/Question/Game3/?roomid=" + roomidglobal +
                "&uname=" + document.getElementById("uname").innerHTML, true);
            xmlhttp.send();
        }
        else {
            alert("Your browser does not support XMLHTTP.");
        }
    }

    
    function state_Change() {
        if (xmlhttp.readyState == 4) {// 4 = "loaded"
            if (xmlhttp.status == 200) {// 200 = OK
                // ...our code here...
                if (xmlhttp.responseText == "yes") {
                    window.location = ip + "/Question/Game/?uname=" +
                        document.getElementById("uname").innerHTML + "&roomid=" + roomidglobal;
                } else {
                    window.location = ip + "/Home/Room/?uname=" +
                   document.getElementById("uname").innerHTML + "&roomid=" + document.getElementById("roomid").innerHTML
                    +"&theflag="+theflag;
                    return;
                }
            } 
        } else {
           
        }
    }
</script>

@{
    ViewBag.Title = "Room";
}

<div class="container" style="height:580px;background-image:url(@Url.Content("~/Images/background.png"))">
    <h2 style="color:white;display:inline">Room:</h2><span style="color:white;font-size:30px" class="text-left" id="roomid">@ViewBag.roomid</span>
    <h2 style="color:white" class ="hide">number:<span id="number">@ViewBag.number</span></h2>
    <p style="color:white" class="text-left">用户名:</p>
    <p style="color:white" class="text-left" id="uname">@ViewBag.name</p>
    <table border=2 style="width:100%;height:200px;">
        <tr style="width:100%;height:50%;">
            @if (@ViewBag.number <= 4)
            {
                for (var i = 0; i < @ViewBag.number; i++)
                {
                    <td style="width:25%">
                        <table style="border-width:0px;width:100%">
                            <tr>
                                <td style="width:50%;text-align:center">
                                    @if (@ViewBag.user[i] != "")
                                    {
                                        <img src="~/Images/user.png"/><p style="color:white">@ViewBag.user[i]</p>
                                    }
                                </td>
                                <td style="width:50%;text-align:center">
                                    @if (@ViewBag.user[i] != "" && @ViewBag.ready[i] == 1)
                                    {
                                        <img src="~/Images/ready.png"/>
                                    }
                                </td>
                            </tr>
                        </table>
                    </td>
                }
                for (var i = @ViewBag.number; i < 4; i++)
                {
                    <td style="width:25%">
                        <table style="border-width:0px;width:100%">
                            <tr>
                                <td style="width:50%;text-align:center">
                                    <img src="~/Images/none.png" />
                                </td>
                                <td style="width:50%;text-align:center">
                                   
                                </td>
                            </tr>
                        </table>
                    </td>
                }
            }
            else
            {
                for (var i = 0; i < 4; i++)
                {
                     <td style="width:25%">
                        <table style="border-width:0px;width:100%">
                            <tr>
                                <td style="width:50%;text-align:center">
                                    @if (@ViewBag.user[i] != "")
                                    {
                                        <img src="~/Images/user.png"/><p style="color:white">@ViewBag.user[i]</p>
                                    }
                                </td>
                                <td style="width:50%;text-align:center">
                                    @if (@ViewBag.user[i] != "" && @ViewBag.ready[i] == 1)
                                    {
                                        <img src="~/Images/ready.png"/>
                                    }
                                </td>
                            </tr>
                        </table>
                    </td>
                }
            }
        </tr>
        <tr style="width:100%;height:50%;">
            @if (@ViewBag.number <= 4)
            {
                for (var i = 0; i < 4; i++)
                {
                    <td style="width:25%">
                        <table style="border-width:0px;width:100%">
                            <tr>
                                <td style="width:50%;text-align:center">
                                    <img src="~/Images/none.png" />
                                </td>
                                <td style="width:50%;text-align:center">
                                   
                                </td>
                            </tr>
                        </table>
                    </td>
                }
            }
            else
            {
                for (var i = 0; i < @ViewBag.number - 4; i++)
                {
                    <td style="width:25%">
                        <table style="border-width:0px;width:100%">
                            <tr>
                                <td style="width:50%;text-align:center">
                                    @if (@ViewBag.user[i + 4] != "")
                                    {
                                        <img src="~/Images/user.png"/><p style="color:white">@ViewBag.user[i + 4]</p>
                                    }
                                </td>
                                <td style="width:50%;text-align:center">
                                    @if (@ViewBag.user[i + 4] != "" && @ViewBag.ready[i + 4] == 1)
                                    {
                                        <img src="~/Images/ready.png"/>
                                    }
                                </td>
                            </tr>
                        </table>
                    </td>
                }
                for (var i = @ViewBag.number - 4; i < 4; i++)
                {
                    <td style="width:25%">
                        <table style="border-width:0px;width:100%">
                            <tr>
                                <td style="width:50%;text-align:center">
                                    <img src="~/Images/none.png" />
                                </td>
                                <td style="width:50%;text-align:center">
                                   
                                </td>
                            </tr>
                        </table>
                    </td>
                }
            }
        </tr>
    </table>
    <div align="right">
        <a href="@Url.Action("Hall", new { userName = @ViewBag.name, need = true, roomid = @ViewBag.roomid })"
        class="button glow button-pill button-flat-royal"><i class="icon-circle-arrow-left icon-large"></i>退出</a>
        <button class="button glow button-pill button-flat-royal" id="roomid1entry" onmousedown="aaaa()">
            <i class="icon-circle-arrow-right icon-large"></i>开始</button>
    </div>
</div>
